package com.cf.r1027_e;

import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class e {

    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StreamTokenizer in = new StreamTokenizer(br);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        in.nextToken(); int T = (int) in.nval;
        while (T-- > 0) {
            solve();
        }
        out.flush();
        out.close();
        br.close();
    }

    static void solve() throws IOException {
        in.nextToken(); n = (int) in.nval;
        a = new int[n];
        for (int i = 0; i < n; i++) {
            in.nextToken(); a[i] = (int) in.nval;
        }
        graph = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            graph.add(new ArrayList<>());
        }
        for (int i = 0; i < n - 1; i++) {
            in.nextToken(); int x = (int) in.nval - 1;
            in.nextToken(); int y = (int) in.nval - 1;
            graph.get(x).add(y);
            graph.get(y).add(x);
        }
        for (int i = 0; i < n; i++) {
            Arrays.fill(f[i], 0L);
        }
        dfs(0, -1);
        for (int i = 0; i < n; i++) {
            out.print(f[i][1] + " ");
        }
        out.println();
    }

    static List<List<Integer>> graph;
    static int MAXN = 200005;
    static int n;
    static long[][] f = new long[MAXN][2];
    static int[] a;

    public static void dfs(int x, int fa) {
        f[x][0] = a[x];
        f[x][1] = a[x];
        if (fa != -1) {
            f[x][0] = Math.min(f[x][0], a[x] - f[fa][1]);
            f[x][1] = Math.max(f[x][1], a[x] - f[fa][0]);
        }
        for (int y : graph.get(x)) {
            if (y == fa) continue;
            dfs(y, x);
        }
    }
}
